home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / funmakel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.3 KB  |  72 lines

  1. /*
  2. \funcref{fun\_makelist}{void fun\_makelist ()}
  3.     {}
  4.     {}
  5.     {newvar(), sortlist()}
  6.     {}
  7.     {funmakel.c}
  8.     {
  9.  
  10.         This function converts the last pushed string into a listvariable
  11.         holding expanded filenames. The {\em reg} register is set to hold the
  12.         list.  The list is alphabetically sorted.
  13.  
  14.         {\bf Note that} under MSDOS, the elements of the list are converted
  15.         to lower case.
  16.  
  17.         The argument at the top of the stack may be, optionally, an
  18.         attribute mask. In this case, the mask is used in a
  19.         {\em findfirst() / findnext ()} loop. By default the
  20.         attribute {\em \_A\_NORMAL} is used.
  21.     }
  22. */
  23.  
  24. #include "icm-exec.h"
  25.  
  26. void fun_makelist ()
  27. {
  28.     register char
  29.         *name;                          /* filemask string */
  30.     register int
  31.         attrib,                         /* attribute to scan for */
  32.         size = 0;                       /* sz of created list */
  33.     char
  34.        *namefound,                      /* returned by findfirst()/next() */
  35.        drive [_MAX_DRIVE],              /* strings to create full */
  36.        dir [_MAX_DIR],                  /* filename, incl. path */
  37.        fname [_MAX_FNAME],
  38.        ext [_MAX_EXT],
  39.        newname [_MAX_PATH];
  40.  
  41.     reg = newvar (e_list);              /* return type: list */
  42.  
  43.     attrib = stack [sp].vu.intval;      /* get function arguments */
  44.     name = stack [sp - 1].vu.i->ls.str;
  45.  
  46.     if (*name)                          /* if valid name.. */
  47.     {
  48.         _splitpath (name, drive, dir, fname, ext);
  49.  
  50.                                         /* find a first name */
  51.         namefound = findfirst (name, attrib);
  52.         while (namefound)               /* as long as that succeeds */
  53.         {
  54.                                         /* make a new path */
  55.             _makepath (newname, drive, dir, namefound, "");
  56.  
  57.                                         /* add entry to the list */
  58. #ifdef MSDOS                            /* under DOS: lower case */
  59.             reg = addtolist (reg, _strlwr (newname));
  60. #else                                   /* under UNIX: case as-is */
  61.             reg = addtolist (reg, newname);
  62. #endif
  63.             size++;                     /* size of the list so far */
  64.  
  65.             namefound = findnext();     /* determine new name */
  66.         }
  67.  
  68.         reg.vu.i->ls.list.size = size;
  69.         reg = sortlist (reg);
  70.     }
  71. }
  72.